import 'package:pacsun/constants/apiConstants.dart' show ApiConstants;
import 'base/apiClient.dart';
import '../model/userLoginModel.dart' show UserLoginModel;
import '../model/userModel.dart' show UserModel;

import '../model/apiResponse.dart';
import 'package:pacsun/model/sysUserTagModel.dart' show YouAreTagModel;

class SysTagsService {
  final ApiClient _apiClient = ApiClient();

  Future<List<YouAreTagModel>> getSysTags() async {
    try {
      String uri = '/api/v1/user/youAreTagList';

      final response =
          await _apiClient.get(uri, headers: ApiConstants.jsonHeaders);

      final apiResponse = ApiResponse<List<dynamic>>.fromJson(
        response.data,
        (data) => data as List<dynamic>,
      );

      if (apiResponse.isSuccess) {
        // Convert each item in the list to YouAreTagModel
        return apiResponse.data
                ?.map((item) =>
                    YouAreTagModel.fromJson(item as Map<String, dynamic>))
                .toList() ??
            [];
      } else {
        throw 'Failed to get tags: ${apiResponse.message}';
      }
    } catch (e) {
      print('=== 请求失败 ===');
      print('Error: $e');
      print('==============');
      throw Exception('$e');
    }
  }
}
